1009B - Minimum Ternary String - CodeForces Solution


greedy implementation *1400

Please click on ads to support us..

C++ Code:

#include<bits/stdc++.h>

using namespace std;
using ll = long long;
using ld = long double;
using str = string;

// Pairs
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using pd = pair<ld,ld>;
#define F first
#define S second

// Vectors
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vl = vector<ll>;
using vd = vector<ld>;
using vs = vector<str>;
using vpi = vector<pi>;
using vpl = vector<pl>;
using vpd = vector<pd>;

#define sz(x) int((x).size())
#define all(x) begin(x),end(x)
#define rall(x) x.rbegin(), x.rend()
#define sor(x) sort(all(x))
#define rsor(x) sort(rall(x))
#define pb(x) push_back(x)

// Complex
const ld PI = acos((ld)-1);
const ld EPS = (1e-10);
typedef complex<double>point;

#define angle(x)  (atan2((x).imag(), (x).real()))
#define vec(x,y)  ((y) - (x))
#define length(x) (hypot((x).imag(), (x).real()))
#define normalize(x) ((x)/length(x))
#define dp(x,y) ((conj(x) * (y)).real()) // dot product, if = 0 -> prep
#define cp(x,y) ((conj(x) * (y)).imag()) // cross product, if = 0 -> parallel
#define same(p1,p2) (dp(vec(p1,p2),vec(p1,p2)) < EPS)
#define lengthSqr(p)  dp(p,p)
#define Rotate_O(p,ang) ((p) * exp(point(0,ang)))
#define Rotate_A(p,ang,about) (Rotate_O(vec(about,p),ang) + about)
#define Reflect_O(v,m) (conj((v) / (m)) * (m))

// Common
#define endl "\n"
#define E cout << -1 << endl;
#define N cout << "NO" << endl;
#define Y cout << "YES" << endl;
#define SetPre(n, x)  cout << fixed << setprecision(n) << x

// Loops
#define F0R(i, a, b) for (int i = (a); i < (b); ++i)
#define FOR(i, a) F0R(i, 0, a)

// Contest
#define tests int t; cin >> t; while(t--)
#define Sonic ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);

int main()
{
    Sonic
    string s ; cin >> s ;
    string sol;
    int i = 0 ;
    for( ; i < sz(s) ; i++ ){
        if( s[i] != '2' ) sol += s[i] ;
        else break ;
    }
    int sum0 = 0;
    string MMMMMMMMMMM;
    for( ; i < sz(s) ; i++ ){
        if( s[i] == '1' ) sol+=s[i];
        else MMMMMMMMMMM += s[i];
    }
    sor(sol);
    sol += MMMMMMMMMMM;
    cout<<sol;
    return 0 ;
}


Comments

Submit
0 Comments
More Questions

148B - Escape
847G - University Classes
1110A - Parity
1215B - The Number of Products
604C - Alternative Thinking
1204C - Anna Svyatoslav and Maps
322A - Ciel and Dancing
1689B - Mystic Permutation
1711B - Party
1702D - Not a Cheap String
1714F - Build a Tree and That Is It
1703F - Yet Another Problem About Pairs Satisfying an Inequality
610A - Pasha and Stick
1200A - Hotelier
1091A - New Year and the Christmas Ornament
1352B - Same Parity Summands
1102A - Integer Sequence Dividing
630B - Moore's Law
1004A - Sonya and Hotels
1680B - Robots
1690A - Print a Pedestal (Codeforces logo)
1295A - Display The Number
1077A - Frog Jumping
1714G - Path Prefixes
1369C - RationalLee
289B - Polo the Penguin and Matrix
1716A - 2-3 Moves
1670B - Dorms War
1716B - Permutation Chain
987A - Infinity Gauntlet